home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / macgzip_03b2-src / macos / think / MacErrors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-09  |  1.6 KB  |  88 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Copyright (C) 1993  SPDsoft
  3.  * 
  4.  */
  5.  
  6. #include <string.h>
  7. #include <errno.h>
  8.  
  9. #define Alert            151
  10. #define Warning            150
  11. #define    ErrResType        'Errs'
  12.  
  13. char _strerr[256];
  14.  
  15. /************************************************************************************/
  16.  
  17. void  Calert( char* theMsg )
  18. {    
  19.     ParamText(CtoPstr(theMsg),"\p","\p","\p");
  20.  
  21.     StopAlert(Alert,NULL);
  22. }
  23.  
  24. int  Cask( char* theMsg )
  25. {
  26.     ParamText(CtoPstr(theMsg),"\p","\p","\p");
  27.     
  28.     return( CautionAlert(Warning,NULL) );
  29. }
  30.  
  31. void    PError( char *s )
  32. {
  33.     Str255 s2;
  34.     Handle myHandle;
  35.     
  36.     sprintf((char*)_strerr,"%s: %s", s, strerror(errno));
  37.     CtoPstr((char*)_strerr);
  38.     
  39.     if ( errno != 0 )
  40.     {
  41.         if((myHandle=GetResource('Errs',errno))==nil)
  42.         {
  43.             NumToString( (long) errno, s2 );
  44.             ParamText((StringPtr)_strerr,"\p",s2,"\p???");
  45.         }    
  46.         else
  47.             ParamText(    (StringPtr)_strerr,
  48.                         "\p",
  49.                         (StringPtr)(*myHandle),
  50.                         (StringPtr)((*myHandle)+**myHandle+1)
  51.                     );
  52.     }
  53.     else ParamText((StringPtr)_strerr,"\p","\p","\p");
  54.  
  55.     StopAlert(Alert,NULL);
  56. }
  57.  
  58. /************************************************************************************/
  59.  
  60.  
  61. void  theAlert( int ErrorInd,int ErrorType, OSErr theOSErr, Boolean exiting)
  62. {
  63.     Str255 s2,s1;
  64.     Handle myHandle;
  65.     
  66.     if (ErrorType!=0) GetIndString( s1, ErrorType, ErrorInd);
  67.     else *s1=0x00;
  68.     
  69.     if ( theOSErr != 0 )
  70.     {
  71.         if((myHandle=GetResource(ErrResType,theOSErr))==nil)
  72.         {
  73.             NumToString( (long) theOSErr, s2 );
  74.             ParamText(s1,"\p",s2,"\p???");
  75.         }    
  76.         else
  77.             ParamText(    s1,
  78.                         "\p",
  79.                         (StringPtr)(*myHandle),
  80.                         (StringPtr)((*myHandle)+**myHandle+1)
  81.                     );
  82.     }
  83.     else ParamText(s1,"\p","\p","\p");
  84.     StopAlert(Alert,NULL);
  85.     if ( exiting ) ExitToShell();
  86. }
  87.  
  88.